/*
********************************************************************************
* Copyright (C) 2022, xiang.D <dx_65535@163.com>.
* All right reserved.
*
* File Name   : main.cc
* Author      :
* Version     : V1.0
* Description :
* Journal     : 2022-03-04 version v1.0
* Brief       : Blog: https://blog.csdn.net/qq_38750572?spm=1001.2014.3001.5343
* Others      :
                Compile command: make
********************************************************************************
*/

#include <stdio.h>
#include <unistd.h>
#include "originator.h"
#include "caretaker.h"

#define MAIN_LOGD(fmt, args...) printf("%d Main D: " fmt, __LINE__, ##args)
#define MAIN_LOGW(fmt, args...) printf("%d Main W: " fmt, __LINE__, ##args)
#define MAIN_LOGE(fmt, args...) printf("%d Main E: " fmt, __LINE__, ##args)
#define MAIN_LOG(fmt, args...)  printf(fmt, ##args)

int main(int argc, char *argv[])
{
    COriginator theOriginator;
    CCaretaker theCCaretaker(&theOriginator);

    MAIN_LOG("---- Backup 1th attribute ----\n");
    SAttrValue attrValue = {10, 100, {0}};
    theOriginator.SetAttribute(&attrValue);
    theCCaretaker.Backup();
    theOriginator.ShowInfo();
    MAIN_LOG("------------------------------\n\n");
    sleep(3);

    MAIN_LOG("---- Backup 2th attribute ----\n");
    attrValue.level = 66;
    attrValue.blood = 80;
    theOriginator.SetAttribute(&attrValue);
    theCCaretaker.Backup();
    theOriginator.ShowInfo();
    MAIN_LOG("------------------------------\n\n");
    sleep(5);

    MAIN_LOG("----- Current attribute  -----\n");
    attrValue.level = 88;
    attrValue.blood = 60;
    theOriginator.SetAttribute(&attrValue);
    theOriginator.ShowInfo();
    MAIN_LOG("------------------------------\n\n");
    sleep(4);

    MAIN_LOG("--> Wating roll back to the previous version\n");
    sleep(2);
    theCCaretaker.Undo();
    theOriginator.ShowInfo();
    MAIN_LOG("------------------------------\n\n");

    MAIN_LOG("--> Wating roll back to the previous version\n");
    sleep(2);
    theCCaretaker.Undo();
    theOriginator.ShowInfo();
    MAIN_LOG("------------------------------\n\n");

    return 0;
}